CUBE CONNECT Edition Help

Opening a CUBE Matrix file with the CubeMatrixFile Class

The below syntax will call and instance of the CubeMatrixFile class, allowing to connect to an existing or new CUBE Matrix file. In the first example, an existing matrix file is opened for investigation or editing.

source_mt = r"input\cube7_matrix\random_matrix_1000.cube-matrix"
mt = cp.CubeMatrixFile(source_mt)
mt.open()

Once the matrix file is opened and the connection to the matrix is established, it is possible to extract several information on the matrix, such as the number of zones giving the dimension of the matrices as below.

zones = mt.zones()

In case that matrix file does not exists, the “Could not open file” error will be returned if using the open method. In this case, when the matrix file needs to be created, then the following syntax can be used instead, specifying the number of zones of the matrices that the matrix file will store.

new_mt = "output/cube7_matrix/random_matrix_1000_multi.cube-matrix"

zones = 1000
mt = cp.CubeMatrixFile(new_mt)
mt.openWithCreate(zones)

It should be noticed that in case that new_mt matrix file already actually exists in that location, then the openWithCreate method will work as the open method and the number of zones that is specified as argument will be ignored.

The openWithTruncate method instead will both create a new file, if this does not exist, but it will also remove the content of an existing file, truncating it, in case this already exists, setting the number of zones to the value imposed as argument, that could be different than the existing one. The example below shows the syntax for this method.

new_or_source_mt = "work/cube7_matrix/random_matrix_1000.cube-matrix"

zones = 100
mt = cp.CubeMatrixFile(new_or_source_mt)
mt.openWithTruncate(zones)

Closing the matrix file can be done with the close method as below.

mt.close()